package 集合;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class t4 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        //迭代器遍历
        Iterator<String> it =list.iterator();
        while(it.hasNext()){
            String s = it.next();
            System.out.print(s);
        }
        System.out.println();
        //增强for遍历
        for(String s : list){
            System.out.print(s);
        }
        System.out.println();
        //普通for遍历
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.print(s);
        }
        System.out.println();
        //lambda 遍历
        list.forEach(s-> System.out.print(s));
        System.out.println();

        //列表迭代器
        ListIterator<String> li = list.listIterator();
        while(li.hasNext()){
            String s = li.next();
            if("bbb".equals(s)){
                li.add("qqq");
            }
        }
        System.out.println(list);
    }
}
